package com.kjtpay.design_pattern.flyweight;

import java.util.Hashtable;

/**
 * 网站工厂；FlyweightFactory
 */
class WebSiteFactory {
    private Hashtable flyweights = new Hashtable();

    // 获得网站分类
    public WebSite getWebSiteCategory(String key) {
        // 如果不存在，创建对象
        if (!flyweights.containsKey(key)) {
            // 以网站的type属性作为key
            flyweights.put(key, new ConcreteWebSite(key));
        }
        return (WebSite)flyweights.get(key);
    }

    // 获得网站分类总数
    public Integer getWebSiteCount() {
        return flyweights.size();
    }
}
